package com.xsmart.entrance.web;

import com.xsmart.common.entity.EcomException;
import com.xsmart.common.entity.RequestBean;
import com.xsmart.common.entity.ResponseBean;
import com.xsmart.common.services.ApiCallService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * api请求入口
 * @author guojd
 */
@CrossOrigin(origins = "*", maxAge = 3600)
@RestController
@RequestMapping("/api")
public class ApiController {
    @Autowired
    private ApiCallService apiCallService;

    @RequestMapping(value = "/{version}/{serviceName}/{methodName}", method = RequestMethod.POST)
    public Object api(@PathVariable String version, @PathVariable String serviceName, @PathVariable String methodName, @ModelAttribute RequestBean requestBean, HttpServletRequest request) throws EcomException {
        return apiCallService.call(version, serviceName, methodName, requestBean, request);
    }


}
